package morncloud.com.notes;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import morncloud.com.notes.ui.DataChangeCallbacks;
import morncloud.com.notes.ui.Utils;

public class MainActivity extends Activity {
    public static final int CODE_RELOAD_VIEW = 100;
    public static final int CODE_RELOAD_OK = 101;
    private DataChangeCallbacks mDataChangeCallbacks;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        Button btnNew = (Button) findViewById(R.id.notes_new);
        btnNew.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, EditNoteActivity.class);
                intent.putExtra(Utils.NOTES_STATUS_KEY,Utils.NOTES_CREATE);
                startActivityForResult(intent, CODE_RELOAD_VIEW);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.e("print", "getTheCode0" + resultCode);
        if(mDataChangeCallbacks!=null&&resultCode==CODE_RELOAD_OK){
            Log.e("print","getTheCode");
            mDataChangeCallbacks.reloadView();
        }
    }

    public void setmDataChangeCallbacks(DataChangeCallbacks mDataChangeCallbacks) {
        this.mDataChangeCallbacks = mDataChangeCallbacks;
    }
}